package com.oracle.interceptor;

import com.oracle.Service.impl.CategoryService;
import com.oracle.pojo.Category;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Transactional
public class CategorysInterceptor extends HandlerInterceptorAdapter {

    @Autowired
    private CategoryService categoryService;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        ServletContext application = request.getServletContext();
        List<Category> list =  categoryService.selectCategorys();
        List<Category> list2 = categoryService.selectCategorys_All();
        if (list!=null){
            application.setAttribute("categorys",list);
        }
        if (list2!=null){
            application.setAttribute("categorysAll",list2);
        }
        return true;
    }
}
